#include<vector>
#include<unordered_set>
using namespace std;

class Solution {
    vector<vector<int>>ops = { {-1,0},{1,0},{0,-1},{0,1} };

    void tryDetect(const vector<vector<char>>& board, vector<vector<int>>&flags, int i, int j) {
        if(board[i][j]!='O'|| flags[i][j] == 1)
            return;
        flags[i][j] = 1;
        for (auto& op : ops) {
            if (i + op[0] < 0 || i + op[0] >= board.size())
                continue;
            if (j + op[1] < 0 || j + op[1] >= board[0].size())
                continue;
            if (board[i + op[0]][j + op[1]] == 'O') {
                tryDetect(board, flags, i + op[0], j + op[1]);
            }

        }
    }

public:
    void solve(vector<vector<char>>& board) {
        if (board.size() < 1) return;
        vector<vector<int>>flags(board.size());
        for (int i = 0; i < board.size(); ++i)
            flags[i].resize(board[0].size());
        for (int i = 0; i < board.size(); ++i) {
            tryDetect(board, flags, i, 0);
            tryDetect(board, flags, i, board[0].size() - 1);
        }
        for (int i = 0; i < board[0].size(); ++i) {
            tryDetect(board, flags, 0, i);
            tryDetect(board, flags, board.size()-1, i);
        }
        for (int i = 0; i < flags.size(); ++i) {
            for (int j = 0; j < flags[i].size(); ++j)
                if (flags[i][j] == 0)
                    board[i][j] = 'X';
        }

    }
};